import axios from '../Utils/axios'
import { message } from 'antd'

const _getProductType = async params => {
    let data = null
    if (params) {
        data = await axios({
            url: '/hsApi/hszcpz/product/findTypeNameByFundId',
            method: 'POST',
            data: JSON.stringify({...params})
        })
    } else {
        message.error("params is null")
    }

    if (data) {
        if (data.status) {
            return data.result
        } else {
            message.error(data.desc)
        }
    } else {
        return { message: 'error', status: false}
    }
}

const _getUserInfo = async params => {
    let data = null
    if (params) {
        data = await axios({
            url: '/hsApi/sso/account/getUserInfoByToken',
            method: 'POST',
            data: JSON.stringify({...params})
        })
    } else {
        message.error("params is null")
    }

    if (data) {
        if (data.status) {
            return data.result
        }
    } else {
        return { message: 'error', status: false}
    }
}

// 检查登录状态
const _checkLogin = async params => {
    let data = null
    if (params) {
        data = await axios({
            url: '/hsApi/sso/account/getLoginStatus',
            method: 'POST',
            data: JSON.stringify({
                ...params
            })
        })
    }

    if (data) {
        return data
    } else {
        return { message: 'error', status: false }
    }
}

// 检查状态
const _checkPermission = async params => {
    let data = null
    if (params) {
        data = await axios({
            url: '/hsth/proInfo/findUserRiskSet',
            method: 'POST',
            data: JSON.stringify({
                ...params
            })
        })
    }

    if (data) {
        return data
    } else {
        return { message: 'error', status: false }
    }
}

export {
    _getProductType,
    _getUserInfo,
    _checkLogin,
    _checkPermission
}
